Skip to content

Sheets: add selection stats (sum, average, count) to sheets bottom bar#493

Open
the-narwhal wants to merge 2 commits intoProtonMail:mainfrom
the-narwhal:main
Open

Sheets: add selection stats (sum, average, count) to sheets bottom bar#493
the-narwhal wants to merge 2 commits intoProtonMail:mainfrom
the-narwhal:main

Conversation

@the-narwhal
Copy link
Copy Markdown

What

Adds a selection statistics display to the Proton Sheets bottom bar, the sum, average, and count that appear in the bottom-right corner when you highlight multiple cells, matching the behaviour of Google Sheets, Excel, and LibreOffice Calc.

Why

This feature existed in the legacy UI via the SheetStatus component from @rowsncolumns/spreadsheet, but was never ported when the new UI was built. There was no comment or TODO indicating it was deliberately dropped, it appears to have simply been missed.

How

  • Added a SelectionStats memo component to BottomBar.tsx. It reads activeSheetId, selections, merges, and getEffectiveValue from useUI((ui) => ui.legacy.*) and renders the stats on the right side of the bar.
  • The useMemo dependencies include getEffectiveValue, which comes from spreadsheetState and gets a new reference after formula recalculation, so stats stay up to date without any extra wiring.
  • Extracted all computation into a standalone selectionStats.ts module (no external dependencies) for clean testability.
  • Gave SheetTabs a flex-1 min-w-0 class so it properly fills the available space and the stats are naturally pinned to the right.

Behaviour

  • Single cell selected → nothing shown
  • Multiple cells with numbers → Sum: X Average: Y Count: Z
  • Mixed numbers and text → Sum and Average reflect only numeric cells; Count reflects all non-empty cells
  • All-empty selection → nothing shown
  • Merged cells → only the owner (top-left) cell is counted, never double-counted
  • Very large selections → processing is capped at 50,000 cells to bound CPU cost
  • Read-only and revision modes → stats are still shown (they're informational only)

Testing

27 unit tests in selectionStats.test.ts covering all of the above cases including edge cases for Infinity, NaN, false, 0, floating-point accumulation artifacts, multi-range aggregation, merge deduplication, the cell cap, and locale-aware number formatting.

Show sum, average, and count in the bottom bar when multiple cells are
selected, matching the behaviour of Google Sheets, Excel, and LibreOffice.

This existed in the legacy UI via SheetStatus from @rowsncolumns/spreadsheet
but was not ported to the new UI.
@the-narwhal the-narwhal marked this pull request as ready for review April 26, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant